package com.dk.controller;

import com.dk.pojo.ArtType;
import com.dk.service.ArtTypeServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("artTypeController")
public class ArtTypeController {

    //文章类型
    @Autowired
    private ArtTypeServiceI artTypeServiceI;

    //跳转查询文章类型
    @RequestMapping("list")
    public String listGet(){
        return "artType/list";
    }

    //查询文章
    @RequestMapping("getInfoServer")
    @ResponseBody
    public List<ArtType> getInfoServer(){
        List<ArtType> list = artTypeServiceI.getInfoServer();
        return list;
    }

    //跳转文章类型增加页面
    @RequestMapping("insertInfo")
    public String insertInfo(){
        return "artType/add";
    }

    //确认增加文章类型
    @RequestMapping("saveById")
    @ResponseBody
    public int saveById(ArtType artType){
        artTypeServiceI.saveById(artType);
        return 1;
    }

    //修改回显文章类型
    @RequestMapping("updateInfo/{typeId}")
    public String updateInfo(@PathVariable("typeId")Integer typeId, Model model){
        ArtType artType = artTypeServiceI.getUpdateById(typeId);
        model.addAttribute("artType",artType);
        return "artType/update";
    }

    //确认修改文章类型
    @RequestMapping("updateById")
    @ResponseBody
    public int updateById(ArtType artType){
        artTypeServiceI.updateById(artType);
        return 1;
    }

    //删除文章类型
    @RequestMapping("deleteById/{typeId}")
    @ResponseBody
    public int deleteById(@PathVariable("typeId")Integer typeId){
        artTypeServiceI.deleteById(typeId);
        return 1;
    }
}
